<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>附件管理</title>
    <link href="__STATIC__/component/pear/css/pear.css" rel="stylesheet"/>
    {include file='public/head.html'}
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
      <table class="layui-hide" id="currentTable" lay-filter="currentTable"
             data-auth-add="{:check_auth('add')}"
             data-auth-edit="{:check_auth('edit')}"
             data-auth-delete="{:check_auth('del')}"
             data-auth-modify="{:check_auth('multi')}"
      ></table>
    </div>
</div>

<script type="text/html" id="picTpl">
    {{- d.type == 'image' ? '<img style="max-width:80px; max-height:30px;" src="'+d.path+'" data-image="'+d.title+'">' : '<img style="max-width:80px; max-height:30px;" src="{:url('ajax/icon')}?suffix='+d.ext+'">' }}
</script>

<script src="__STATIC__/component/layui/layui.js"></script>
<script src="__STATIC__/component/pear/pear.js"></script>
<script>
    layui.use(['aphpTable'], function () {
        var aphpTable = layui.aphpTable;
        var host = window.location.protocol + '//' + window.location.host;
        var typeList = {:select_list(widget('dict')->get('attach_type'))};

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: "{:url('add')}",
            delete_url: "{:url('del')}",
            modify_url: "{:url('multi')}",
        };

        aphpTable.render({
            init: init,
            url: "{:url('index')}",
            where: { where: location.search.slice(1) },
            toolbar: ['refresh_table', 'add', 'enable', 'disable', 'delete'],
            search: true,
            quickSearch: 'name|mime@like#搜索',
            cols: [
                [
                    {type: 'checkbox'},
                    {title: '排序', field: 'sort', edit: 'text', search: false},
                    {title: 'ID', field: 'id'},
                    {title: '名称', field: 'title', edit: 'text', searchOp: 'like'},
                    {title: '图片', field: 'path', templet: '#picTpl', search: false},
                    {
                        title: '路径',
                        field: 'path',
                        templet: '<div><span class="copy" title="复制" data-copy-text="' + host + '{{d.path}}">复制 <i class="layui-icon layui-icon-file-b"></i></span></div>',
                        search: false
                    },
                    {title: '大小', field: '_size', search: false},

                    {title: 'Mime类型', field: 'mime', searchOp: 'like'},
                    {title: '类型', field: 'type', templet: aphpTable.formatter.label, selectList: typeList},
                    {title: '上传时间', field: 'upload_time', templet: aphpTable.formatter.datetime, search: 'range'},
                    {
                        title: '状态',
                        field: 'status',
                        align: 'center',
                        unresize: true,
                        templet: aphpTable.formatter.switch
                    },
                    {
                        title: '操作',
                        align: 'center',
                        width: 120,
                        templet: aphpTable.formatter.tool,
                        operat: ['delete']
                    }
                ]
            ],
            page: {}
        });
        aphpTable.bindEvent();

    });
</script>
</body>
</html>